package com.java.dormitorymanager.mvc.view;

import com.java.dormitorymanager.pojo.Dorm;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

/**
 * @program: DormitoryManager
 * @description: 显示查询后的宿舍结果
 * @author: ShuangChenYue
 * @create: 2021-05-19 08:32
 **/
@WebServlet(value = "/ViewDormWithSearch")
public class ViewDormWithSearchServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("您已进入宿舍查询页面");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();

        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<head>");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>查询宿舍结果</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-dorm/showDorm.css\">");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-other/doIcon.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\">Manage Dorm</h1>");
        out.println("</div>");

        out.println("<div id=\"div01\">");
        out.println("<h3 class=\"ListName\">Dorm</h3>");
        out.println("<table class=\"table01\">");
        out.println("<tr class=\"tr01\">");
        out.println("<td>ID</td>");
        out.println("<td>宿舍编号</td>");
        out.println("<td>人数</td>");
        out.println("<td>类型</td>");
        out.println("<td>分数</td>");
        out.println("<td>操作</td>");
        out.println("</tr>");
        Dorm dorm = (Dorm) req.getAttribute("dorm");
             out.println("<tr class=\"tr02\">");
            out.println("<td style=\"text-align: center\">"+dorm.getId()+"</td>");
            out.println("<td>"+dorm.getDornum()+"</td>");
            out.println("<td>"+dorm.getAmount()+"</td>");
            out.println("<td>"+dorm.getType()+"</td>");
            out.println("<td>"+dorm.getScore()+"</td>");
            out.println("<td><a href=\"/DormitoryManager/mvc/toUpdateDormInfo.do?dornum="+dorm.getDornum()+"&id="+dorm.getId()+"\"><i class=\"iconfontU alterIcon\" title=\"修改信息\">&#xe700;</i></a> <a href=\"/DormitoryManager/mvc/deleteDormByDornum.do?dornum="+dorm.getDornum()+"\"><i class=\"iconfontU deleteIcon\" title=\"删除\">&#xe614;</i></a> <a href=\"/DormitoryManager/mvc/showDormDetail.do?dornum="+dorm.getDornum()+"\"><i class=\"iconfontU infoIcon\" title=\"详情\">&#xe611;</i></a> <a href=\"/DormitoryManager/mvc/addScoreToDorm.do?dornum="+dorm.getDornum()+"&score="+dorm.getScore()+"\"><i class=\"iconfontU scoreIcon\" title=\"打分\">&#xe606;</i></a> <a href=\"/DormitoryManager/mvc/toAddMSToDorm.do?dormNumber="+dorm.getDornum()+"\"><i class=\"iconfontU addStudentIcon\" title=\"添加学生至本宿舍\">&#xe61f;</i></a></td>");
            out.println("</tr>");
        out.println("</table>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
